package edu.suda.xsap.service.impl;


import edu.suda.xsap.dto.MemCardBindDto;

import edu.suda.xsap.dto.MemCardDto;
import edu.suda.xsap.dto.MemberDto;
import edu.suda.xsap.dto.convert.MemCardBindConvert;

import edu.suda.xsap.entity.MemCardBind;
import edu.suda.xsap.mapper.MemCardBindMapper;
import edu.suda.xsap.service.MemCardBindService;
import edu.suda.xsap.service.MemCardService;
import edu.suda.xsap.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MemCardBindServiceImpl implements MemCardBindService {
    @Autowired
    private MemCardBindConvert memCardBindConvert;

    @Autowired
    private MemCardBindMapper memCardBindMapper;
    @Autowired
    private MemberService memberService;

    @Autowired
    private MemCardService memCardService;

    @Override
    public void save(MemCardBind memCardBind) {

        Integer memberID = memCardBind.getMemberId();
        List<MemberDto> members = memberService.findById(memberID);
        memCardBind.setMemberName(members.get(0).getMemberName());

        Integer cardID = memCardBind.getCardId();
        List<MemCardDto> memberCards = memCardService.findById(cardID);
        memCardBind.setMemberCardName(memberCards.get(0).getMemberCardName());

        memCardBindMapper.save(memCardBind);
    }

    @Override
    public List<MemCardBindDto> findAll() {
        //
        List<MemCardBind> memCardBinds = memCardBindMapper.findAll();
//        System.out.println("============================");
//        System.out.println(memCardBinds);
//        System.out.println("============================");
        //要把这个List<Log>转换成List<LogDto>
        return memCardBindConvert.toDtoList(memCardBinds);
    }


}
